const fs = require('fs');
const request = require('request');
const config = require('../config');
const getToken = require('./getToken');

//请求二维码的参数  
var postData = {
  path: "pages/index/index",
  scene:'',
  width: 430,
  auto_color:true,
}
var createQrcode = function (ctx) {
  var self=this;
  return getToken(ctx.state.$wxInfo.userinfo.openId).then(token=>{
    //设置请求参数postData.path/scene

    //生成二维码
    getQrcode(token);
    return {
      status: '0',
      msg: data
    }
  })
  

}
//查询已有token 返回{hastoken:true,token:''}
getexisttoken = function () {

}

  //生成二维码  
  getQrcode = function (access_token) {
    console.log('fn：getQrcode');
      postData = JSON.stringify(postData);
      request({
        method: 'POST',
        url: 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + access_token.data.access_token,
        body: postData
      }).pipe(fs.createWriteStream('./public/images/index.png'));//路径自己定义吧  
  }

module.exports = createQrcode;